//
//  DnImageProccessingMenu.m
//  DnRollTabbarMenu
//
//  Created by Ngoc on 23/12/2011.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "FirstViewController.h"


@implementation FirstViewController (Menu) //DnImageProccessingMenu 
//============================================================================================
// Demo
-(UIView*) getCropMenuItem:(NSInteger) itemIndex
{
    UIView *returnView=nil;
    UIImage *normalItemImg;
    NSString *title;
    DnButton *button;
    SEL selectedHandler;
    title =  @"";
    normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
    NSInteger xCor=0, yCor=0, width = kMenuItemWidth, height = kMenuItemHeight;
    switch (itemIndex) {
        case 0:            
        {
            xCor = 6;
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Straighten";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 1:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Freedom";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 2:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Square";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 3:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"3x2";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 4:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"4x6";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 5:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"3x4";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 6:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"4x3";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 7:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"3x5";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 8:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"5x3";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 9:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"5x7";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 10:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"7x5";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 11:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"4x5";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 12:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"5x4";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 13:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"16x9";
            selectedHandler = @selector(showMessage:);
            break;
        } 
    }
    button = [[DnButton alloc] initWithFrame:CGRectMake(xCor, yCor, width , height) title:title backgroundImage:normalItemImg autoResize:YES];
    
    [button setTitleColor:[UIColor colorWithRed:67.0f/255.0f green:70.0f/255.0f blue:59.0f/255.0f alpha:1.0] forState:UIControlStateNormal ] ;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted|UIControlStateSelected];
    [button.titleLabel setFont:[UIFont fontWithName:@"Papyrus-Bold" size:16.0]];
    [button addTarget:self action:selectedHandler forControlEvents:UIControlEventTouchUpInside];
    button.tag = itemIndex;
    returnView = [button retain];
    [button release];
    return returnView;
}
-(UIView*) getAdjustMenuItem:(NSInteger) itemIndex
{
    UIView *returnView=nil;
    UIImage *normalItemImg;
    NSString *title;
    DnButton *button;
    SEL selectedHandler;
    title =  @"";
    normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
    NSInteger xCor=0, yCor=0, width = kMenuItemWidth, height = kMenuItemHeight;
    switch (itemIndex) {
        case 0:            
        {
            xCor = 6;
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Rotate Left";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 1:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Rotate Right";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 2:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Flip V";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 3:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Flip H";
            selectedHandler = @selector(showMessage:);
            break;
        } 
    }
    button = [[DnButton alloc] initWithFrame:CGRectMake(xCor, yCor, width , height) title:title backgroundImage:normalItemImg autoResize:YES];
    
    [button setTitleColor:[UIColor colorWithRed:67.0f/255.0f green:70.0f/255.0f blue:59.0f/255.0f alpha:1.0] forState:UIControlStateNormal ] ;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted|UIControlStateSelected];
    [button.titleLabel setFont:[UIFont fontWithName:@"Papyrus-Bold" size:16.0]];
    [button addTarget:self action:selectedHandler forControlEvents:UIControlEventTouchUpInside];
    button.tag = itemIndex;
    returnView = [button retain];
    [button release];
    return returnView;
    
}

-(UIView*) getEffectMenuItem:(NSInteger) itemIndex
{
    UIView *returnView=nil;
    UIImage *normalItemImg;
    NSString *title;
    DnButton *button;
    SEL selectedHandler;
    title =  @"";
    normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
    NSInteger xCor=0, yCor=0, width = kMenuItemWidth, height = kMenuItemHeight;
    switch (itemIndex) {
        case 0:            
        {
            xCor = 6;
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Color";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 1:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"X";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 2:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Y";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 3:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Z";
            selectedHandler = @selector(showMessage:);
            break;
        } 
    }
    button = [[DnButton alloc] initWithFrame:CGRectMake(xCor, yCor, width , height) title:title backgroundImage:normalItemImg autoResize:YES];
    
    [button setTitleColor:[UIColor colorWithRed:67.0f/255.0f green:70.0f/255.0f blue:59.0f/255.0f alpha:1.0] forState:UIControlStateNormal ] ;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted|UIControlStateSelected];
    [button.titleLabel setFont:[UIFont fontWithName:@"Papyrus-Bold" size:16.0]];
    [button addTarget:self action:selectedHandler forControlEvents:UIControlEventTouchUpInside];
    button.tag = itemIndex;
    returnView = [button retain];
    [button release];
    return returnView;
    
}
-(UIView*) getBorderMenuItem:(NSInteger) itemIndex
{
    UIView *returnView=nil;
    UIImage *normalItemImg;
    NSString *title;
    DnButton *button;
    SEL selectedHandler;
    title =  @"";
    normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
    NSInteger xCor=0, yCor=0, width = kMenuItemWidth, height = kMenuItemHeight;
    switch (itemIndex) {
        case 0:            
        {
            xCor = 6;
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"W";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 1:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"X";
            selectedHandler = @selector(showMessage:);
            break;
        } 
        case 2:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Y";
            selectedHandler = @selector(showMessage:);
            break;
        }
        case 3:            
        {
            normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
            title =  @"Z";
            selectedHandler = @selector(showMessage:);
            break;
        } 
    }
    button = [[DnButton alloc] initWithFrame:CGRectMake(xCor, yCor, width , height) title:title backgroundImage:normalItemImg autoResize:YES];
    
    [button setTitleColor:[UIColor colorWithRed:67.0f/255.0f green:70.0f/255.0f blue:59.0f/255.0f alpha:1.0] forState:UIControlStateNormal ] ;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted|UIControlStateSelected];
    [button.titleLabel setFont:[UIFont fontWithName:@"Papyrus-Bold" size:16.0]];
    [button addTarget:self action:selectedHandler forControlEvents:UIControlEventTouchUpInside];
    button.tag = itemIndex;
    returnView = [button retain];
    [button release];
    return returnView;
    
}
-(UIView*) getDemoItemView:(NSInteger) menuIndex itemIndex:(NSInteger) itemIndex
{
    UIImage *normalItemImg = [UIImage imageNamed: @"19-gear.png" ];
    NSString *title;
    DnButton *button;
    title =  [NSString stringWithFormat:@"%d - %d",menuIndex,itemIndex];
    button = [[DnButton alloc] initWithFrame:CGRectMake(0, 0, kMenuItemWidth , kMenuItemHeight) title:title backgroundImage:normalItemImg autoResize:YES];
    
    [button setTitleColor:[UIColor colorWithRed:67.0f/255.0f green:70.0f/255.0f blue:59.0f/255.0f alpha:1.0] forState:UIControlStateNormal ] ;
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted|UIControlStateSelected];
    [button.titleLabel setFont:[UIFont fontWithName:@"Papyrus-Bold" size:16.0]];
    
    return button;
}
//==========================================================================================

- (UIColor *) randomColor {
    CGFloat red =  (CGFloat)random()/(CGFloat)RAND_MAX;
    CGFloat blue = (CGFloat)random()/(CGFloat)RAND_MAX;
    CGFloat green = (CGFloat)random()/(CGFloat)RAND_MAX;
    return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}
// Menu Datasource
-(UIView*) menu:(NSInteger) menuIndex itemAtIndex:(NSInteger) itemIndex
{
    UIView *returnView;
    switch (menuIndex) {
        case 0:
            returnView = [self getCropMenuItem:itemIndex];
            break;
        case 1:
            returnView = [self getAdjustMenuItem:itemIndex];
            break;
        case 2:
            returnView = [self getEffectMenuItem:itemIndex];
            break;
        case 3:
            returnView = [self getBorderMenuItem:itemIndex];
            break;        
    }
    return returnView;
}

-(UIView*) navigationMenuItemAtIndex:(NSInteger)itemIndex
{
    UIView *returnView;
    UIButton *button;
    
    button = [UIButton buttonWithType:UIButtonTypeCustom];
    //button = [[GradientButton alloc]initWithFrame:CGRectMake(0, 0, KMenuNavigationItemWidth , kMenuNavigationItemHeight)];
    button.frame = CGRectMake(0, 0, KMenuNavigationItemWidth , kMenuNavigationItemHeight);
    //NSString *title = [NSString stringWithFormat:@"Menu %d",itemIndex]; 
    //[button setTitleColor:[self randomColor] forState:UIControlStateNormal ] ;
    //button.backgroundColor = [UIColor clearColor];
    UIImage *normalImage, *selectedImage;
    switch (itemIndex) 
    { 
        case 0:
        {
            //title = @"Crop";
            selectedImage = [UIImage imageNamed:@"crops.png"];
            normalImage = [UIImage imageNamed:@"crops_sl.png"];
            break;
        }
        case 1:
        {
            //title = @"Adjust";
            normalImage = [UIImage imageNamed:@"adjust.png"];
            selectedImage = [UIImage imageNamed:@"adjust_sl.png"];            
            break;
        }
        case 2:
        {
            //title = @"Effects";
            normalImage = [UIImage imageNamed:@"effects.png"];
            selectedImage = [UIImage imageNamed:@"effects_sl.png"];            
            break;
        }
        case 3:
        {
            //title = @"Border";
            normalImage = [UIImage imageNamed:@"borders.png"];
            selectedImage = [UIImage imageNamed:@"borders_sl.png"];            
            break;
        }
    }
    //[button setTitle:title forState:UIControlStateNormal];
    [button setImage:normalImage forState:UIControlStateNormal];
    [button setImage:selectedImage forState:UIControlStateSelected ];
    returnView = button;
    return returnView;
    
}
-(NSInteger) numberOfMenus
{
    return 4;
}
-(NSInteger) numberItemsOfMenu:(NSInteger) menuIndex
{
    NSInteger count =0;
    switch (menuIndex) {
        case 0:
        {
            count = 14;
            break;
        } 
        case 1:
        {
            count = 4;
            break;
        }
        case 2:
        {
            count = 4;
            break;
        }
        case 3:
        {
            count = 4;
            break;
        }
    }
    return count;
}

@end
